package cn.dg.manager.goods.goodsIntroduction.service.impl;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.dg.manager.base.util.DateUtil;
import cn.dg.manager.base.util.QRCodeUtil;
import cn.dg.manager.common.entity.PageEntity;
import cn.dg.manager.goods.goodsIntroduction.dao.GoodsInfoDao;
import cn.dg.manager.goods.goodsIntroduction.entity.GoodsInfoVO;
import cn.dg.manager.goods.goodsIntroduction.service.GoodsIntroductionService;

@Service("goodsIntroductionService")
public class GoodsIntroductionServiceImpl implements  GoodsIntroductionService {
	
	@Autowired
	GoodsInfoDao goodsInfoDao;
	
	/**
	 * 检索商品基本信息
	 */
	public PageEntity<GoodsInfoVO> getGoodsInfoListPage(Map<String, Object> condMap) {
		PageEntity<GoodsInfoVO> list = goodsInfoDao.findGoodsInfoListPage(condMap);
        return list;
	}

	/**
	 * 增加商品基本信息
	 * 
	 * @param bean
	 * @param contextPath
	 * @param url
	 * @return
	 */
	public long insertGoodsInfo(GoodsInfoVO bean, String realPath, String url) {
		String fileName = QRCodeUtil.BASE_FILE_PATH.concat(DateUtil.getSdfTimesSSS()).concat(".png");
		
		// logo图片
		File logoFile = new File(realPath.concat(QRCodeUtil.LOGO_FILE_PATH));
		// 生成商品二维码图
		File newQRCodeFile = new File(realPath.concat(fileName));
		QRCodeUtil.drawLogoQRCode(logoFile, newQRCodeFile, url, bean.getGoodName());
		bean.setGoodQrcodeImageUrl(fileName);
		return goodsInfoDao.insertGoodsInfo(bean);
	}
	
	/**
	 * 
	 */
	public long updateGoodsInfo(GoodsInfoVO bean) {
		return goodsInfoDao.updateGoodsInfo(bean);
	}

	/**
	 * 删除商品基本信息
	 */
	public long deleteGoodsInfo(List<String> goodsIdList) {
		return goodsInfoDao.deleteGoodsInfo(goodsIdList);
	}

	/**
	 * 根据主键查询数据
	 */
	public GoodsInfoVO findGoodsInfoById(Map<String, Object> condMap) {
		return goodsInfoDao.findGoodsInfoById(condMap);
	}

	public long updateGoodsImageInfo(Map<String, Object> condMap) {
		return goodsInfoDao.updateGoodsImageInfo(condMap);
	}
}
